Micron Document
Livres et Wikis | Archives | Info


Java bytecode
part 2/8 Β· 23.1 KB total
layout: Wide Β· Narrow Β· Centered
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Relation to Java

In general, a Java programmer does not need to understand Java bytecode or even be aware of it. However, as suggested in the IBM developerWorks journal, "Understanding bytecode and what bytecode is likely to be generated by a Java compiler helps the Java programmer in the same way that knowledge of assembly helps the C or C++ programmer."cite-ref-4[4]

Instruction set architecture

The bytecode comprises various instruction types, including data manipulation, control transfer, object creation and manipulation, and method invocation, all integral to Java's object-oriented programming model.cite-ref-oracle-jvm-spec-1-1[1]

The JVM is both a stack machine and a register machine. Each frame for a method call has an "operand stack" and an array of "local variables".cite-ref-jvm-5-0[5] cite-ref-jvm-book-2-1[2] The operand stack is used for passing operands to computations and for receiving the return value of a called method, while local variables serve the same purpose as registers and are also used to pass method arguments. The maximum size of the operand stack and local variable array, computed by the compiler, is part of the attributes of each method.cite-ref-jvm-5-1[5] Each can be independently sized from 0 to 65535 values, where each value is 32 bits. long and double types, which are 64 bits, take up two consecutive local variablescite-ref-jvm-5-2[5] (which need not be 64-bit aligned in the local variables array) or one value in the operand stack (but are counted as two units in the depth of the stack).cite-ref-jvm-5-3[5]

Instruction set

Each bytecode is composed of one byte that represents the opcode, along with zero or more bytes for operands.cite-ref-jvm-5-4[5]

Of the 256 possible byte-long opcodes, as of 2015, 202 are in use (~79%), 51 are reserved for future use (~20%), and 3 instructions (~1%) are permanently reserved for JVM implementations to use.cite-ref-jvm-5-5[5] Two of these (impdep1 and impdep2) are to provide traps for implementation-specific software and hardware, respectively. The third is used for debuggers to implement breakpoints.

Instructions fall into a number of broad groups:

β€’ Load and store (e.g. aload_0, istore)
β€’ Arithmetic and logic (e.g. ladd, fcmpl)
β€’ Type conversion (e.g. i2b, d2i)

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────